require 'xm/platform'
require 'fileutils'
#原始jar文件目录
provider_lib_dir = XM::Platform.root.join("comps/xafsvc/metric_provider")
#拷贝后jar文件目录
share_lib_dir = XM::Platform.root.join("comps/xafsvc/share_lib")

if File.exist?(provider_lib_dir) then
   Dir.glob(File.join(provider_lib_dir,"*.jar")).each{|file| FileUtils.cp_r(file, share_lib_dir)}
   Dir.glob(File.join(provider_lib_dir,"*.jar")).each{|file| File.delete(file)}
end
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
gc_log = XM::Platform.config.comps["xafsvc"].root.join("containers/jetty/log/gc.log")
error_log = XM::Platform.config.comps["xafsvc"].root.join("containers/jetty/log/error_#{timestamp}.log")
group :component do
  java(:xafsvc, "comps/xafsvc/containers/jetty",
       :order => 88,
       :stdout =>"NUL",
       :start => {
           :jar => "start.jar",
	   :arguments => "-Dconf=../../conf/global.properties"
       },
       :started => {:heartbeat => "8082", :url => "/moc",:max => 3.minutes},
       :stopped => {:max => 30.seconds},
       :debug =>"2016",
       :java_options => %W{-XX:MaxPermSize=#{xaf_perm} -Xms#{xaf_min} -Xmx#{xaf_max}  -XX:+ScavengeBeforeFullGC -XX:+UseGCOverheadLimit -XX:+UseTLAB -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+PrintPromotionFailure -Xloggc:#{gc_log} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=5M -XX:ErrorFile=#{error_log} -DSTOP.PORT=8078 -DSTOP.KEY=secret -DAPI_VISIT_PROTECTION=protection.xml},
       :jmx => "30198",
       :mandatory => true,
       :stop => :kill
  )
end

##  jmx port 9016